<template>
    <div id="home">
        <div class="userinfo flex-nowrap">
            <a href="#/user/set" class="userinfo-thumb-bg"><img src="/statics/home/images/header.jpg" alt="头像" class="userinfo-thumb"></a>
            <a href="#/user/set" class="userinfo-info">
                <p><span>{{ userInfo.username }}</span><img src="/statics/home/images/user-edit.png" alt="编辑" class="userinfo-edit"></p>
                <p>{{ userInfo.phone }}</p>
            </a>
        </div>
        <div class="userinfo-btns flex-wrap">
            <a href="#/account/index" class="userinfo-item flex-nowrap">
                <img src="/statics/home/images/user-coin2.png" alt="代币">
                <p>
                    代币
                    <span class="color-main">{{ userInfo.money }}</span>
                </p>
            </a>
            <div @click="toGameRecharge()" class="userinfo-item flex-nowrap">
                <img src="/statics/home/images/user-game.png" alt="进入游戏">
                <p>进入游戏</p>
            </div>
            <a href="#/good/list" class="userinfo-item flex-nowrap">
                <img src="/statics/home/images/user-order.png" alt="装备交易">
                <p>装备交易</p>
            </a>
            <a href="#/good/release/list" class="userinfo-item flex-nowrap">
                <img src="/statics/home/images/user-good.png" alt="装备管理">
                <p>装备管理</p>
            </a>
            <a href="#/withdraw/index" class="userinfo-item flex-nowrap">
                <img src="/statics/home/images/user-withdraw.png" alt="提现">
                <p>提现</p>
            </a>
            <a href="#/user/info" class="userinfo-item flex-nowrap">
                <img src="/statics/home/images/user-info.png" alt="信息维护">
                <p>信息维护</p>
            </a>
            <a href="#" class="userinfo-item flex-nowrap">
                <img src="/statics/home/images/user-kf.png" alt="客服">
                <p>客服</p>
            </a>
        </div>
        <div class="btn-1 btn-1-logout" @click="logout()">退出登录</div>
        <p class="copyright">V 1.0.0</p>
    </div>
</template>

<script>
import { LOGOUT } from '.././store/mutation_types'
export default {
    name: 'Home',
    data() {
        return {
            userInfo:{
                username:'',
                phone:'',
                money:0
            },
        }
    },
    computed: {
        // 登录状态
        username() {
            return this.$store.getters.user_id != 0 ? this.$store.getters.user_name : '未登录'
        },
    },
    created() {
        this.$api.user.info({}).then(res => {
            this.userInfo = res.result
            // 必须先认证
            if(res.result.idcard == "" || res.result.idcard == null){
                this.$router.push('/cert');
            }
        }).finally(e => {});
    },
    methods: {
        logout() {
            this.$api.user.logout({}).then(res => {
                this.$store.commit(LOGOUT)
                // 跳转到登录
                this.$router.push('/login');
            }).finally(e => {});
        },
        toGameRecharge(){
            this.$router.push({
                name:'GameRecharge',
                params:{
                    coin:11,
                    money:1
                },
            });
        },
    }
}
</script>
  